package com.yusi.controller;


import com.yusi.entity.Airplane;
import com.yusi.entity.dto.RespBean;
import com.yusi.service.IAirplaneService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yusi
 * @since 2022-01-05
 */
@RestController
@RequestMapping("/air/info")
public class AirplaneController {

    @Autowired
    private IAirplaneService iAirplaneService;

    @ApiOperation("查看飞机类型")
    @GetMapping("/")
    public List<Airplane> getAirPlane(){
        return iAirplaneService.list();
    }

    @ApiOperation("新增飞机类型")
    @PostMapping("/")
    public RespBean saveAirPlane(@RequestBody Airplane airplane){
        airplane.setIsenable(1);
        if(iAirplaneService.save(airplane)) {
            return RespBean.success("添加成功！");
        }
        return RespBean.error("添加失败！");
    }

    @ApiOperation("删除飞机类型")
    @DeleteMapping("/{id}")
    @Transactional
    public RespBean delAirPlane(@PathVariable Integer id){
        System.out.println(id);
        if (iAirplaneService.removeById(id)){
            return RespBean.success("删除成功！");
        }
        return RespBean.error("删除失败！");
    }

    @ApiOperation("修改飞机类型")
    @PutMapping("/")
    @Transactional
    public RespBean updAriPlane(@RequestBody Airplane airplane){
        if (iAirplaneService.updateById(airplane)){
            return RespBean.success("修改成功！");
        }
        return RespBean.error("修改失败！");
    }



}
